package com.zhong.thesimpleconnection.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.zhong.thesimpleconnection.service.ServiceToMonitorFile;

/**
 * Created by 俊峰 on 2017/5/18.
 * 监听手机是否开机，如果开机则启动应用中必要的服务
 * 开机自启的服务
 */

public class StartServiceWhenThePhoneStart extends BroadcastReceiver {

    private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION_BOOT)){
            start(context);
        }
    }

    private void start(Context context) {
        Intent startMyService = new Intent(context, ServiceToMonitorFile.class);
        context.startService(startMyService);
    }
}
